<?php
declare(strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Filesystem;

class CleanPosterFiles extends Command
{
    protected function configure()
    {
        $this->setName('clean:poster')
            ->setDescription('Clean temporary poster files');
    }
    
    protected function execute(Input $input, Output $output)
    {
        $storage = public_path() . 'storage/poster/';
        
        // 获取所有临时文件
        $files = glob($storage . '{demo_qrcode_*,preview_*,invite_*}.png', GLOB_BRACE);
        
        $count = 0;
        foreach ($files as $file) {
            // 删除24小时前的临时文件
            if (time() - filemtime($file) > 86400) {
                unlink($file);
                $count++;
            }
        }
        
        $output->writeln("Cleaned {$count} temporary poster files");
    }
} 